#include "intro.h"

Intro::Intro() 
{

}

/*-------------------------------------------------------------------------------------------------------------*/
Intro::~Intro() 
{

}

/*-------------------------------------------------------------------------------------------------------------*/
bool Intro::Initialize()
{
	// We load the intro
	if (!Sprite::LoadIni("data/graphics/intro.spr"))
	{
		return false;
	}

	m_iStage = INTRO_STAGE_FADEIN;

	m_currentColor = D3DCOLOR_ARGB(0,0xFF,0xFF,0xFF);

	m_fAccum = 0.0f;

	return true;
}

/*-------------------------------------------------------------------------------------------------------------*/
void Intro::Update(float fDt) 
{
	Sprite::Update(fDt);

	m_fAccum += fDt;

	if (KeyDown(DIK_ESCAPE) || KeyDown(DIK_RETURN)) 
	{
		m_iStage = INTRO_STAGE_FADEOUT;
	}

	switch(m_iStage) 
	{
		case INTRO_STAGE_FADEIN:
			if (m_fAccum > INTERVAL_TIME)
			{
				m_currentColor += D3DCOLOR_ARGB(0x1,0,0,0);
				if (m_currentColor >= D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF)) 
				{
					m_currentColor = D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF);
					m_iStage = INTRO_STAGE_WAIT;
				}
				m_fAccum -= INTERVAL_TIME;
			}
			break;

		case INTRO_STAGE_WAIT:
			if (m_fAccum > WAIT_TIME) 
			{
				m_iStage = INTRO_STAGE_FADEOUT;
				m_fAccum -= WAIT_TIME;
			}
			break;

		case INTRO_STAGE_FADEOUT:
			if (m_fAccum > INTERVAL_TIME)
			{
				m_currentColor -= D3DCOLOR_ARGB(0x1,0,0,0);

				if (m_currentColor <= D3DCOLOR_ARGB(0,0xFF,0xFF,0xFF)) 
				{
					m_currentColor = D3DCOLOR_ARGB(0,0xFF,0xFF,0xFF);
					m_iStage = INTRO_STAGE_NONE;
				}
				m_fAccum -= INTERVAL_TIME;
			}
			break;
	}
}

/*-------------------------------------------------------------------------------------------------------------*/
void Intro::Draw() 
{
	g_renderer.EnableModulate();
	g_renderer.SetModulationColor(m_currentColor);

	Sprite::Draw();
	
	g_renderer.DisableModulate();
}


